#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os


def get_ebin_dirs(build_dir):
    result = []
    for maindir, subdir_list, file_name_list in os.walk(build_dir):
        for file_name in file_name_list:
            if file_name.endswith(".beam"):
                file_base_name = os.path.splitext(file_name)[0]
                result.append(file_base_name)
    return result


def generate_module_interpret_info(module_name):
    info = "int:ni(%s)," % module_name
    return info


if __name__ == "__main__":
    lib_base_dir = "_build/default/lib/"
    current_dir = os.path.dirname(os.path.realpath(__file__))
    project_path = os.path.join(os.path.abspath(os.path.join(current_dir, "..")), "")

    dirname = os.path.join(project_path, lib_base_dir)
    file_list = get_ebin_dirs(dirname)
    print("复制下面的命令到 on_app_start.escript 里面, 否则垮模块不能直接触发断点调试\n")

    for file in file_list:
        info = generate_module_interpret_info(file)
        print(info)